package com.longdaji.decoration.utils;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.longdaji.decoration.R;

/**
 * Created by Kanade on 2018/4/24 0024.
 */

public class ConstellationDialog extends Dialog implements View.OnClickListener {

    private ImageView ivImageOne, ivImageTwo, ivImageThree, ivImageFour, ivImageFive, ivImageSix, ivImageSeven, ivImageEight,
            ivImageNine, ivImageTen, ivImageEleven, ivImageTwelve;
    private TextView tvOne, tvTwo, tvThree, tvFour, tvFive, tvSix, tvSeven, tvEight, tvNine, tvTen, tvEleven, tvTwelve;
    private TextView tvCancel, tvConfirm;
    private Context mContext;
    private int chosen = 0;

    public ConstellationDialog(@NonNull Context context) {
        this(context, 0);
//        this.mContext = context;
//        initView();
    }

    public ConstellationDialog(@NonNull Context context, int themeResId) {
        super(context, R.style.ConstellationTheme);
        this.mContext = context;
        initView();
    }


    private void initView() {
        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.dialog_constellation, null);
        setContentView(view);
        ivImageOne = view.findViewById(R.id.iv_img_one);
        ivImageTwo = view.findViewById(R.id.iv_img_two);
        ivImageThree = view.findViewById(R.id.iv_img_three);
        ivImageFour = view.findViewById(R.id.iv_img_four);
        ivImageFive = view.findViewById(R.id.iv_img_five);
        ivImageSix = view.findViewById(R.id.iv_img_six);
        ivImageSeven = view.findViewById(R.id.iv_img_seven);
        ivImageEight = view.findViewById(R.id.iv_img_eight);
        ivImageNine = view.findViewById(R.id.iv_img_nine);
        ivImageTen = view.findViewById(R.id.iv_img_ten);
        ivImageEleven = view.findViewById(R.id.iv_img_elven);
        ivImageTwelve = view.findViewById(R.id.iv_img_twelve);
        tvOne = view.findViewById(R.id.tv_cons1);
        tvTwo = view.findViewById(R.id.tv_cons2);
        tvThree = view.findViewById(R.id.tv_cons3);
        tvFour = view.findViewById(R.id.tv_cons4);
        tvFive = view.findViewById(R.id.tv_cons5);
        tvSix = view.findViewById(R.id.tv_cons6);
        tvSeven = view.findViewById(R.id.tv_cons7);
        tvEight = view.findViewById(R.id.tv_cons8);
        tvNine = view.findViewById(R.id.tv_cons9);
        tvTen = view.findViewById(R.id.tv_cons10);
        tvEleven = view.findViewById(R.id.tv_cons11);
        tvTwelve = view.findViewById(R.id.tv_cons12);
        tvCancel = view.findViewById(R.id.tv_cancel);
        tvConfirm = view.findViewById(R.id.tv_confirm);
        tvOne.setOnClickListener(this);
        tvTwo.setOnClickListener(this);
        tvThree.setOnClickListener(this);
        tvFour.setOnClickListener(this);
        tvFive.setOnClickListener(this);
        tvSix.setOnClickListener(this);
        tvSeven.setOnClickListener(this);
        tvEight.setOnClickListener(this);
        tvNine.setOnClickListener(this);
        tvTen.setOnClickListener(this);
        tvEleven.setOnClickListener(this);
        tvTwelve.setOnClickListener(this);
        tvCancel.setOnClickListener(this);
        tvConfirm.setOnClickListener(this);

    }


    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_cons1:
                // TODO: 2018/4/26 0026 换成以下写法，替换refreshImage，写个chosen2Iv()
//                Glide.with(mContext).load(R.mipmap.circle_unchecked).into(chosen);
                chosen = 1;
                refreshImage();
                Glide.with(mContext).load(R.mipmap.circle_checked).into(ivImageOne);
                break;
            case R.id.tv_cons2:
                chosen = 2;
                refreshImage();
                Glide.with(mContext).load(R.mipmap.circle_checked).into(ivImageTwo);
                break;
            case R.id.tv_cons3:
                chosen = 3;
                refreshImage();
                Glide.with(mContext).load(R.mipmap.circle_checked).into(ivImageThree);
                break;
            case R.id.tv_cons4:
                chosen = 4;
                refreshImage();
                Glide.with(mContext).load(R.mipmap.circle_checked).into(ivImageFour);
                break;
            case R.id.tv_cons5:
                chosen = 5;
                refreshImage();
                Glide.with(mContext).load(R.mipmap.circle_checked).into(ivImageFive);
                break;
            case R.id.tv_cons6:
                chosen = 6;
                refreshImage();
                Glide.with(mContext).load(R.mipmap.circle_checked).into(ivImageSix);
                break;
            case R.id.tv_cons7:
                chosen = 7;
                refreshImage();
                Glide.with(mContext).load(R.mipmap.circle_checked).into(ivImageSeven);
                break;
            case R.id.tv_cons8:
                chosen = 8;
                refreshImage();
                Glide.with(mContext).load(R.mipmap.circle_checked).into(ivImageEight);
                break;
            case R.id.tv_cons9:
                chosen = 9;
                refreshImage();
                Glide.with(mContext).load(R.mipmap.circle_checked).into(ivImageNine);
                break;
            case R.id.tv_cons10:
                chosen = 10;
                refreshImage();
                Glide.with(mContext).load(R.mipmap.circle_checked).into(ivImageTen);
                break;
            case R.id.tv_cons11:
                chosen = 11;
                refreshImage();
                Glide.with(mContext).load(R.mipmap.circle_checked).into(ivImageEleven);
                break;
            case R.id.tv_cons12:
                chosen = 12;
                refreshImage();
                Glide.with(mContext).load(R.mipmap.circle_checked).into(ivImageTwelve);
                break;
            case R.id.tv_cancel:
                dismiss();
                break;
            case R.id.tv_confirm:
                switch (chosen) {
                    case 1:
                        mConstellationListener.onConstellationClick("摩羯座");
                        break;
                    case 2:
                        mConstellationListener.onConstellationClick("白羊座");
                        break;
                    case 3:
                        mConstellationListener.onConstellationClick("处女座");
                        break;
                    case 4:
                        mConstellationListener.onConstellationClick("双子座");
                        break;
                    case 5:
                        mConstellationListener.onConstellationClick("巨蟹座");
                        break;
                    case 6:
                        mConstellationListener.onConstellationClick("天秤座");
                        break;
                    case 7:
                        mConstellationListener.onConstellationClick("水瓶座");
                        break;
                    case 8:
                        mConstellationListener.onConstellationClick("射手座");
                        break;
                    case 9:
                        mConstellationListener.onConstellationClick("双鱼座");
                        break;
                    case 10:
                        mConstellationListener.onConstellationClick("狮子座");
                        break;
                    case 11:
                        mConstellationListener.onConstellationClick("金牛座");
                        break;
                    case 12:
                        mConstellationListener.onConstellationClick("天蝎座");
                        break;
                    default:
                        break;
                }
                dismiss();
                break;
            default:
                break;
        }
    }

    private void refreshImage() {
        Glide.with(mContext).load(R.mipmap.circle_unchecked).into(ivImageOne);
        Glide.with(mContext).load(R.mipmap.circle_unchecked).into(ivImageTwo);
        Glide.with(mContext).load(R.mipmap.circle_unchecked).into(ivImageThree);
        Glide.with(mContext).load(R.mipmap.circle_unchecked).into(ivImageFour);
        Glide.with(mContext).load(R.mipmap.circle_unchecked).into(ivImageFive);
        Glide.with(mContext).load(R.mipmap.circle_unchecked).into(ivImageSix);
        Glide.with(mContext).load(R.mipmap.circle_unchecked).into(ivImageSeven);
        Glide.with(mContext).load(R.mipmap.circle_unchecked).into(ivImageEight);
        Glide.with(mContext).load(R.mipmap.circle_unchecked).into(ivImageNine);
        Glide.with(mContext).load(R.mipmap.circle_unchecked).into(ivImageTen);
        Glide.with(mContext).load(R.mipmap.circle_unchecked).into(ivImageEleven);
        Glide.with(mContext).load(R.mipmap.circle_unchecked).into(ivImageTwelve);

    }

    public interface ConstellationListener {
        void onConstellationClick(String cons);
    }

    private ConstellationListener mConstellationListener;

    public void setConstellationListener(ConstellationListener listener) {
        this.mConstellationListener = listener;
    }
}
